package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class EmpController {
    @GetMapping("/show")
    public String show(){
        int i=0;
        i = i /i;
        return "index.jsp";
    }
//ajax 的写法
    @RequestMapping(value = "/check",produces="text/plain;charset=UTF-8")
    @ResponseBody //ajax不跳页面直接返回字符串
    public String check1(String name){
        if(name.equals("admin")){
            return "用户名已存在,hello";
        }
        return "bjk你真棒";
    }

    //ajax 的写法
    @RequestMapping(value = "/check/{aa}",produces="text/plain;charset=UTF-8")
    @ResponseBody //ajax不跳页面直接返回字符串
    public String check2(@PathVariable("aa") String name){
        if(name.equals("admin")){
            return "用户名已存在,hello~~~~~~~~~~`";
        }
        return "可以注册,ok~~~~~~~~~~`";
    }

    @ExceptionHandler
    public String error(RuntimeException e){
        return "error2.jsp";
    }
}
